﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using FinPlusAssembler;
using QLNet;
using p = FinPlusCompQuant.QLConvParser;

namespace FinPlusCompQuant
{
    public class SwaptionTrade : Trade
    {
        public Trade VanillaSwap { get; private set; }

        //construct
        public SwaptionTrade(string marketName, string cacheName, string id, string curveName, string volSurfName, double nominal, DateTime start, 
            DateTime maturity, double strike, string payRec, string index, double spread, string  fixLegFrq, string fltLegFrq, string fixLegConv,  
            string fltLegConv, string fixLegDayCount, string fltLegDayCount, string holidays, bool endOfMonth = false)
        {
            Id = id;
            var market = Markets.Instance.GetMarket(marketName);
            var cache = Caches.Instance.GetCache(cacheName);
            var indx = market.GetIndex(index);
            var type = p.PayRec(payRec).EnumParse<QLNet.VanillaSwap.Type>();
            var calendar = p.Calendar(holidays);
		
		    var fixedSchedule = new Schedule(start, maturity, new Period(p.Freq(fixLegFrq)), calendar, p.BizConv(fixLegConv), p.BizConv(fixLegConv), DateGeneration.Rule.Forward, endOfMonth);
            var floatSchedule = new Schedule(start, maturity, new Period(p.Freq(fltLegFrq)), calendar, p.BizConv(fltLegConv), p.BizConv(fltLegConv), DateGeneration.Rule.Forward, endOfMonth);
            var vanillaSwapStrike = new VanillaSwap(type, nominal, fixedSchedule, strike, p.DayCount(fixLegDayCount), floatSchedule, indx, spread, p.DayCount((fltLegDayCount)));
		
		    var europeanExercise = new EuropeanExercise(start);
            Underlying = new QLNet.Swaption(vanillaSwapStrike, europeanExercise);

            cache.Add(id, this, volSurfName);
        }
    }
}
